﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using weikebuluo.DAL;
using weikebuluo.Model;
using weikebuluo.Common;

namespace weikebuluo.web.admin.order
{
    public partial class ordadd : weikeweixin.web.admin.cs.adminbase
    {
        TB_DK_ProList_DAL prolistdal = new TB_DK_ProList_DAL();
        protected TB_DK_ProList_Model prolistmodel = new TB_DK_ProList_Model();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                prolistmodel = prolistdal.GetModel(int.Parse(Request.QueryString["id"]));
            }

            switch (Request.Form["action"])
            {
                case "add":
                    add();
                    break;
            }
        }
        private void add()
        {
            if (!string.IsNullOrEmpty(Request.Form["id"]))
            {
                prolistmodel = prolistdal.GetModel(int.Parse(Request.Form["id"]));
            }
            prolistmodel.ProName = Request.Form["ProName"];
            prolistmodel.ProTitle = Request.Form["ProTitle"];
            prolistmodel.ProRemark = Request.Form["ProRemark"];
            prolistmodel.ProUrl = Request.Form["ProUrl"];
            prolistmodel.user_id = int.Parse(user_id);

            if (!string.IsNullOrEmpty(Request.Form["id"]))
            {
                bool re = prolistdal.Update(prolistmodel);
                if (re)
                {
                    Response.Write("{\"errno\":\"0\",\"tip\":\"保存成功！\",\"url\":\"ordlist.aspx\",\"error\":\"\"}");
                }
                else
                {
                    Response.Write("{\"errno\":\"0\",\"tip\":\"保存失败！\",\"url\":\"ordadd.aspx\",\"error\":\"\"}");
                }
                Response.End();
            }
            else
            {
                int re = prolistdal.Add(prolistmodel);
                if (re > 0)
                {
                    Response.Write("{\"errno\":\"0\",\"tip\":\"保存成功！\",\"url\":\"ordlist.aspx\",\"error\":\"\"}");
                }
                else
                {
                    Response.Write("{\"errno\":\"0\",\"tip\":\"保存失败！\",\"url\":\"ordadd.aspx\",\"error\":\"\"}");
                }

                Response.End();
            }
        
        }
    }
}